import sys
import os

pwd = os.path.dirname(os.path.abspath(__file__))
sys.path.append(pwd + '../')
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mxshop.settings')

import django
django.setup()

from goods import GoodsCategory
from db_tools.data.category_data import row_data

for row in row_data:
    goods_category = GoodsCategory()
    goods_category.name = row['name']
    goods_category.code = row['code']
    goods_category.category_type = 1
    goods_category.save()

    for child in row['sub_categorys']:
        goods_category2 = GoodsCategory()
        goods_category2.name = child['name']
        goods_category2.code = child['code']
        goods_category2.parent_category = goods_category
        goods_category2.category_type = 2
        goods_category2.save()

        for child2 in child['sub_categorys']:
            goods_category3 = GoodsCategory()
            goods_category3.name = child2['name']
            goods_category3.code = child2['code']
            goods_category3.parent_category = goods_category2
            goods_category3.category_type = 3
            goods_category3.save()

goods_category = GoodsCategory.objects.all()
print(goods_category)